﻿package view.mainUI.powerview
{
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import consts.*;
    import flash.display.*;
    import flash.events.*;
    import flash.external.*;
    import flash.geom.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.*;
    import view.*;
    import view.uilt.*;

    public class NewPowerView extends powerViewUI
    {
        private var sp:Sprite;
        private var movesp:Sprite;
        private var addsp:Sprite;
        private var movecPanel:Sprite;
        private var attPanel:AttPanelCtrl;
        private var maskSP:Sprite;
        private var _baseX:int = 180;
        private var _power:PowerMove;
        private var rolehead:Image;
        private var _powbgmc:XMLMovieClip;
        private var _mc1:XMLMovieClip;
        private var _mc2:XMLMovieClip;
        private var _mc3:XMLMovieClip;
        private var _loading1:Boolean = false;
        private var _loading2:Boolean = false;
        private var _loading3:Boolean = false;
        private var _xml1:XML;
        private var _xml2:XML;
        private var _xml3:XML;
        private var type:int = 0;
        private var imgname:String = "";
        private var _curimg:String = null;
        private var runing:Boolean = false;
        private var currun:int = 0;
        private var cfgvip:Array;
        private var oPower:int = 0;
        public var oldPower:int = 1;
        private var curpower:int = 0;
        public static const effectxml1:Class = NewPowerView_effectxml1;
        public static const effectxml2:Class = NewPowerView_effectxml2;
        public static const powerbg:Class = NewPowerView_powerbg;
        public static const chongzhiXML:Class = NewPowerView_chongzhiXML;
        private static const HEAD_URL:String = "assets/images/head/";

        public function NewPowerView()
        {
            return;
        }// end function

        override protected function initialize() : void
        {
            var _loc_5:Image = null;
            var _loc_6:Image = null;
            super.initialize();
            this.rolehead = new Image();
            this.rolehead.x = 0;
            this.rolehead.y = -25;
            this.addChild(this.rolehead);
            var _loc_1:* = new Sprite();
            _loc_1.graphics.beginFill(16777215, 1);
            _loc_1.graphics.drawCircle(0, 0, 40);
            _loc_1.graphics.endFill();
            _loc_1.x = 45;
            _loc_1.y = 40;
            this.sp = new Sprite();
            this.sp.x = 260 - 512 >> 1;
            this.sp.y = 90 - 512 >> 1;
            this.sp.mouseEnabled = false;
            this.addChild(this.sp);
            this.initEvent();
            this.movecPanel = new Sprite();
            this.movecPanel.x = this._baseX + 20;
            this.movecPanel.y = 52;
            this.addChild(this.movecPanel);
            this.movesp = new Sprite();
            var _loc_2:int = 0;
            while (_loc_2 <= 9)
            {
                
                _loc_5 = new Image();
                _loc_5.url = "png.common.exp_" + _loc_2.toString();
                _loc_5.y = 24 * _loc_2;
                this.movesp.addChild(_loc_5);
                _loc_2++;
            }
            var _loc_3:int = 0;
            while (_loc_3 <= 9)
            {
                
                _loc_6 = new Image();
                _loc_6.url = "png.common.exp_" + _loc_3.toString();
                _loc_6.y = 24 * (_loc_2 + 1) + 24 * 9;
                this.movesp.addChild(_loc_6);
                _loc_3++;
            }
            this.maskSP = new Sprite();
            this.maskSP.graphics.beginFill(16711680, 1);
            this.maskSP.graphics.drawRect(0, 0, 50, 23);
            this.maskSP.graphics.endFill();
            this.addChild(this.maskSP);
            this.movesp.mask = this.maskSP;
            this.movecPanel.addChild(this.movesp);
            this.addsp = new Sprite();
            this.addsp.x = this._baseX + 20;
            this.addsp.y = 52;
            this.addChild(this.addsp);
            this._xml1 = new XML(new effectxml1());
            this._xml2 = new XML(new effectxml2());
            this._power = new PowerMove();
            this._power.y = 52;
            this._power.x = this._baseX + 20;
            this.addChild(this._power);
            App.leisureMloader.loadSWF(Config.getUrl("assets/images/mainui/powerbg.swf", ResourceType.NORMAL), 1, new Handler(this.mcLoaded));
            this._xml3 = new XML(new chongzhiXML());
            var _loc_4:String = "assets/images/mainui/chongzhi.swf";
            App.mloader3.loadSWF(Config.getUrl(_loc_4), 1, new Handler(this.completeFunc));
            if (Config.hexie == false)
            {
                vipBtn.visible = true;
            }
            else
            {
                vipBtn.visible = false;
            }
            return;
        }// end function

        private function mcLoaded(param1) : void
        {
            this._powbgmc = new XMLMovieClip("powerbg", new XML(new powerbg()));
            this._powbgmc.play();
            this._powbgmc.interval = 1000 / 8;
            this._powbgmc.blendMode = BlendMode.ADD;
            this._powbgmc.mouseEnabled = false;
            this._powbgmc.x = 40;
            this.addChild(this._powbgmc);
            return;
        }// end function

        private function completeFunc(param1:Object) : void
        {
            this._mc3 = new XMLMovieClip("png.chongzhi", this._xml3);
            this._mc3.play();
            this._mc3.interval = 1000 / 10;
            this._mc3.blendMode = BlendMode.ADD;
            this._mc3.mouseEnabled = false;
            this._mc3.x = chongzhiBtn.x - 35;
            this._mc3.y = chongzhiBtn.y - 27;
            this.addChild(this._mc3);
            return;
        }// end function

        private function initEvent() : void
        {
            att0.addEventListener(MouseEvent.CLICK, this.attclickHandler);
            att1.addEventListener(MouseEvent.CLICK, this.attclickHandler);
            att2.addEventListener(MouseEvent.CLICK, this.attclickHandler);
            att3.addEventListener(MouseEvent.CLICK, this.attclickHandler);
            att4.addEventListener(MouseEvent.CLICK, this.attclickHandler);
            att0.addEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            att1.addEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            att2.addEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            att3.addEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            att4.addEventListener(MouseEvent.MOUSE_OVER, this.onOver);
            att0.addEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            att1.addEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            att2.addEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            att3.addEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            att4.addEventListener(MouseEvent.MOUSE_OUT, this.onOut);
            bianqiaoBtn.addEventListener(MouseEvent.CLICK, this.onBianQiang);
            vipBtn.addEventListener(MouseEvent.CLICK, this.vipHandler);
            chongzhiBtn.addEventListener(MouseEvent.CLICK, this.onChongzhi);
            GlobalLayer.instance.root.addEventListener(MouseEvent.CLICK, this.closeAttPanel);
            return;
        }// end function

        private function closeAttPanel(event:MouseEvent) : void
        {
            if (this.type == 1)
            {
                if (this.attPanel == null)
                {
                    this.attPanel = new AttPanelCtrl();
                    this.addChild(this.attPanel);
                    this.attPanel.visible = false;
                }
                this.attPanel.x = att0.x;
                this.attPanel.y = att0.y + 20;
                this.attPanel.visible = !this.attPanel.visible;
                ModelProxy.change("guide", "hide", GuideType.GUIDE_ZD);
                this.type = 2;
            }
            else if (this.attPanel && this.attPanel.visible == true)
            {
                this.attPanel.visible = false;
            }
            return;
        }// end function

        private function attclickHandler(event:MouseEvent) : void
        {
            this.type = 1;
            return;
        }// end function

        private function onOver(event:MouseEvent) : void
        {
            var _loc_2:String = null;
            var _loc_3:* = (event.currentTarget as Button).localToGlobal(new Point(0, 0));
            switch(event.currentTarget)
            {
                case att0:
                {
                    _loc_2 = MColor.getHMTL("和平攻击模式", 7) + "\n不会伤害任何玩家或npc守卫\n" + MColor.getHMTL("切换攻击状态(快捷键h)", 7);
                    break;
                }
                case att1:
                {
                    _loc_2 = MColor.getHMTL("善恶攻击模式", 12) + "\n可以伤害任何红名玩家\n" + MColor.getHMTL("切换攻击状态(快捷键h)", 7);
                    break;
                }
                case att2:
                {
                    _loc_2 = MColor.getHMTL("全体攻击模式", 21) + "\n可以伤害任何玩家或npc守卫\n" + MColor.getHMTL("切换攻击状态(快捷键h)", 7);
                    break;
                }
                case att3:
                {
                    _loc_2 = MColor.getHMTL("组队攻击模式", 4) + "\n可以伤害自己队员以外的所有玩家\n" + MColor.getHMTL("切换攻击状态(快捷键h)", 7);
                    break;
                }
                case att4:
                {
                    _loc_2 = MColor.getHMTL("行会攻击模式", 10) + "\n可以伤害本行会之外的其他玩家\n" + MColor.getHMTL("切换攻击状态(快捷键h)", 7);
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (_loc_2)
            {
                ModelProxy.change("tips", "normal", {data:_loc_2, p:_loc_3});
            }
            return;
        }// end function

        private function onOut(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        private function onBianQiang(event:MouseEvent) : void
        {
            var _loc_2:* = (event.currentTarget as Button).localToGlobal(new Point(0, 0));
            ModelProxy.change("plugin", "change", {target:"gameactive", point:_loc_2, data:2});
            return;
        }// end function

        public function loadMovie() : void
        {
            return;
        }// end function

        public function updatelevel(param1:int = 0) : void
        {
            var _loc_2:Object = null;
            if (param1 == 0)
            {
                _loc_2 = ModelProxy.getValue("data", "user");
                param1 = _loc_2.level;
            }
            levelLabel.text = param1 + "级";
            return;
        }// end function

        public function iniPower() : void
        {
            var _loc_1:* = UserData.getUserData();
            nameLabel.text = _loc_1.name;
            levelLabel.text = _loc_1.level + "级";
            cancerLabel.text = "【" + UIGlobel.getCareer(ModelProxy.getValue("data", "user.career")) + "】";
            this.imgname = _loc_1.career + "_" + _loc_1.sex;
            if (this._curimg != this.imgname)
            {
                this._curimg = this.imgname;
                this.rolehead.url = Config.getUrl(HEAD_URL + this.imgname + ".png");
            }
            this.setPkState(ModelProxy.getValue("data", "user.pkstate"));
            this.showPower(_loc_1.ability.nbValue + _loc_1.abilityBuf.nbValue);
            return;
        }// end function

        private function vipHandler(event:MouseEvent) : void
        {
            ModelProxy.change("plugin", "open", {target:"viptq"});
            return;
        }// end function

        private function onChongzhi(event:MouseEvent) : void
        {
            if (!ItemUilt.canpay)
            {
                ModelProxy.change("movetips", "error", "功能尚未开放，敬请期待");
                return;
            }
            ExternalInterface.call("topay");
            return;
        }// end function

        public function setPkState(param1:int) : void
        {
            var _loc_2:* = UserData.getUserData();
            _loc_2.pkstate = param1;
            var _loc_3:int = 0;
            while (_loc_3 <= 4)
            {
                
                (this["att" + _loc_3.toString()] as Button).visible = false;
                _loc_3++;
            }
            (this["att" + param1.toString()] as Button).visible = true;
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_ZD, this["att" + param1.toString()]);
            switch(param1)
            {
                case 0:
                {
                    typeLabel.text = "和平";
                    break;
                }
                case 1:
                {
                    typeLabel.text = "善恶";
                    break;
                }
                case 2:
                {
                    typeLabel.text = "全体";
                    break;
                }
                case 3:
                {
                    typeLabel.text = "组队";
                    break;
                }
                case 4:
                {
                    typeLabel.text = "行会";
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function showPower(param1:int) : void
        {
            var _loc_2:Point = null;
            if (param1 >= this.oPower)
            {
                _loc_2 = new Point(60 + 20, -30);
            }
            else
            {
                _loc_2 = new Point(60 + 20, 20 + 30);
            }
            this._power.showPower(param1, this.oPower, _loc_2);
            this.oPower = param1;
            return;
        }// end function

        public function chanePkModel() : void
        {
            var _loc_1:* = ModelProxy.getValue("data", "user.pkstate");
            if (_loc_1 < 4)
            {
                this.setPkState((_loc_1 + 1));
                ModelProxy.change("zone", "pkstate", (_loc_1 + 1));
            }
            else
            {
                this.setPkState(0);
                ModelProxy.change("zone", "pkstate", 0);
            }
            return;
        }// end function

    }
}
